package com.flying.planewar;

import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.util.EnumSet;
import java.util.concurrent.BrokenBarrierException;

/**
 * @author 刘鹏飞
 * @Classname Plane
 * @Date 2024/12/17 19:21
 * @Created by 刘鹏飞
 * @Description 飞机类
 */
public class Plane extends GameObject{
    boolean left,right,up,down;  // 飞机的移动方向
    boolean live=true;
    public Plane(Image image, double x, double y,int speed) {
        super(image, x, y,speed);
    }

    @Override
    public void drawMyself(Graphics g) {
        if (!live){
            return;
        }
        super.drawMyself(g);
//        this.x+=3;
        // 改变飞机位置
        if (left){
            x-=speed;
        } else if (right) {
            x+=speed;
        } else if (up) {
            y-=speed;
        }else if (down){
            y+=speed;
        }
    }

    /**
     * 增加飞机方向 ,按下键盘改变飞机方向
     * @param e
     */
    public void addDirection(KeyEvent e) {
        switch (e.getKeyCode()) {
            case KeyEvent.VK_LEFT:
                left = true;
                break;
            case KeyEvent.VK_UP:
                up = true;
                break;
            case KeyEvent.VK_RIGHT:
                right = true;
                break;
            case KeyEvent.VK_DOWN:
                down = true;
                break;
            default:
                break;
        }
    }

    /**
     *
     * @param e
     */
    public void minusDirection(KeyEvent e) {
        switch (e.getKeyCode()) {
            case KeyEvent.VK_LEFT:
                left = false;
                break;
            case KeyEvent.VK_UP:
                up = false;
                break;
            case KeyEvent.VK_RIGHT:
                right = false;
                break;
            case KeyEvent.VK_DOWN:
                down = false;
                break;
            default:
                break;
        }
    }


    // 增加鼠标跟随动作

    public void changePositonMouse(MouseEvent e) {
        System.out.println("haha");
        this.x=e.getX();
        this.y=e.getY();
    }




}
